<?
include("includes/functions.php");
$fileDir = $user_dir.$sub_dir.'/';

$someFile     = $_FILES['image']['tmp_name'];
$someFileName = $_FILES['image']['name'];
$someFileType = $_FILES['image']['type'];
$someFileSize = $_FILES['image']['size'];

$levelPath    = $_POST[levelPath];
$title        = fieldToDB($_POST[title]);
$desc         = fieldToDB($_POST[desc]);

$filename = stripslashes($someFileName);
$filename = cleanFilename($filename);	

// Determine mime type
if ($_POST[uploadSingle] == 1) {
	if ( 
		($someFileType == "application/pdf")    || 
		($someFileType == "text/plain")         || 
		($someFileType == "application/plain")  || 
		($someFileType == "application/msword") ||
		($someFileType == "application/excel")
	   ) {
		$goodFile = 1;
		$filePath = $rootDir.'docs/'.$filename;
	} else { 
		$errorFile   = 1; 
		$errorMessage = 'Only upload MS Word, Text, Excel or PDF files. Thanks.'; 
	}

	if ($errorFile != 1) {
		if(move_uploaded_file($someFile, $filePath)){		
					
			// Add logo file to database
			$sql = "INSERT into transLinks (
					Path,
					Title,
					LinkDescription,
					Link,
					DateCreated,
					Status
					) values (
					'$levelPath',
					'$title',
					'$desc',
					'docs/".$filename."',
					'".date('Y-m-d')."',
					'1'
					)";
			$result = mysql_db_query($dbname,$sql);
			
		}	
	}	
}	
?>

<html><head>
<script type="text/javascript">
var par = window.parent.document;
var progressDiv = par.getElementById('progressBarSingle');
progressDiv.innerHTML = '';

<? if ( ($_POST[uploadSingle] == 1) && ($errorFile != 1) ) { ?>
	
<? } elseif ($errorFile == 1) { ?>
	progressDiv.innerHTML = '<img src="images/iconError.gif"> <?=$errorMessage; ?>';
<? } ?>
function uploadSingleFunction(){
	var par = window.parent.document;
	var iframe = par.getElementById('uploadSingle');
			
	var progressDiv = par.getElementById('progressBarSingle');
	progressDiv.innerHTML = '<img src="images/ajaxAnimBar.gif">';
		
	// send
	document.iform.submit();	
}
</script>
<head>
<style>
body {
	background: #fff;
}
td,p,table,tr,input,select,textarea {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 68.75%;
}
</style>
<body>
<form name="iform" method="post" enctype="multipart/form-data">
<input type="hidden" name="uploadSingle" value="1">
<input type="hidden" name="levelPath" value="<?=$_GET[levelPath]; ?>">
<input id="file" type="file" name="image" size="30" style="font-size: 10px;" />
<div style="padding-top: 3px;"><input type="submit" onClick="uploadSingleFunction();" value="Upload"></div>
</form>
</html>